$('#save_btn').on('click', function () {
    var data = [];
    var field_name = [];
    var field_data = [];
    var i = 0;
    var j = 0;
    var k = 0;

    $('[class="filed-line"]').each(function () {
        i = 0;
        field_data = [];
        $(this).find('.field_content').each(function () {
            field_data[i] = $(this).val();
            i++;
        })
        j = 0;
        field_name = [];
        $(this).find('.colunm_name').each(function () {
            field_name[j] = $(this).text();
            j++;
        })
        data[k] = field_data;
        k++;
        // console.log($(this).find('.field_content'))
    })
    if (field_name.length == 0) {
        layer.msg('字段为空');
        return false;
    }
    if (data.length == 0) {
        layer.msg('数据为空');
        return false;
    }

    var db_name = $('#db_name_input').val();
    var table_name = $('#table_name_input').val();
    var postData = {
        db_name: db_name,
        table_name: table_name,
        field: JSON.stringify(field_name),
        data: JSON.stringify(data),
        _token: $('meta[name="csrf-token"]').attr('content'),
    }
    var res = sendAjaxRequest('POST', '/database/insertNewData', postData, false);
    if (res.status == 0) {
        layer.msg('保存成功', {icon: 1});
        gotoPage('/index/record?db_name=' + db_name + '&table_name=' + table_name);
    } else {
        layer.msg('操作失败，请检查数据', {
            icon: 5,
            time: 10000,
            anim: 6,
            closeBtn: 1,
        });
    }
})


function deleteLine(that) {
    $(that).parent().parent().remove();
}